package com.codingvip.component;

import com.codingvip.utils.DBContext;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 多数据源切换
 */
@Component
@Aspect
public class MultiDataSourceInterceptor {
    @Before("execution(* com.codingvip.service.*.*(..))")
    public void beforeAdvice(JoinPoint joinPoint) {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        if (method.getName().equals("getOrder")) {
            DBContext.setDBKey("db_main");
            System.out.println("update DB_MAIN");
        }

        System.out.println("xxxxxxx");

    }
}
